﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace K9Nano.Extensions;

public static class QueryableExtensions
{
    public static IQueryable<T> WhereIf<T>(this IQueryable<T> source, bool condition, Expression<Func<T, bool>> predicate)
    {
        return condition
            ? source.Where(predicate)
            : source;
    }

    public static IQueryable<T> WhereIfOrElse<T>(this IQueryable<T> source, bool condition, Expression<Func<T, bool>> ifPredicate, Expression<Func<T, bool>> elsePredicate)
    {
        return condition
            ? source.Where(ifPredicate)
            : source.Where(elsePredicate);
    }
}
